package com.sduept.nwld.dataserver.interceptors;

import com.sduept.cim.ledger.manager.EquipmentLedgerManager;
import com.sduept.cim.ledger.manager.SubstationLedgerManager;
import org.springframework.beans.factory.annotation.Autowired;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class CimModeDeleteInterceptor {

	@Autowired
	private SubstationLedgerManager stationLedgerM;
	@Autowired
	private EquipmentLedgerManager ledgerM;
	
	@AroundInvoke
	public Object methodInterceptor(InvocationContext ctx) throws Exception {
		Object[] parameter = ctx.getParameters();
		String id = parameter[0].toString();
		if(parameter[1].toString().contains("Substation")) {
			stationLedgerM.deleteSubstationLedgerBySubstationId(id);
		} else if (parameter[1].toString().contains("ACLineSegment") || parameter[1].toString().contains("DcLinesegment")) {
			ledgerM.deleteByEquipmentId(id);
		}
		return ctx.proceed();
	}
}
